<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>添加单词</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon"
          href="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/basic/favicon.ico">
    <link rel="stylesheet" th:href="@{/css/mouse.css}">
    <link rel="stylesheet" th:href="@{/js/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">序号</label>
        <div class="layui-input-block">
            <input type="number" name="wordrank" lay-verify="required|number" lay-reqtext="必须填写数字！" placeholder="请输入序号"
                   value=""
                   class="layui-input">
            <tip>序号可以随意填写，但是尽量不填！</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">单词</label>
        <div class="layui-input-block">
            <input type="text" name="headword" lay-verify="required|wordjudge" lay-reqtext="必须填写单词" placeholder="请输入单词"
                   value=""
                   class="layui-input">
            <tip>必须填写单词!</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">例句</label>
        <div class="layui-input-block">
            <input type="text" name="sentences" placeholder="请输入例句" value="{'sContent': 'null', 'sCn': 'null'}"
                   class="layui-input">
            <tip>例句可以不填，但不能修改默认的格式(修改null值即可)！</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">短语</label>
        <div class="layui-input-block">
            <input type="text" name="phrases" placeholder="请输入短语" value="{'pContent': 'null', 'pCn': 'null'}"
                   class="layui-input">
            <tip>短语可以不填，但不能修改默认语格式(修改null值即可)！</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">美式发音</label>
        <div class="layui-input-block">
            <input type="text" name="usphone" placeholder="请输入美式发音" value=""
                   class="layui-input">
            <!--            <tip>短语可以不填，但是不能修改默认的短语格式！</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">美式发音接口</label>
        <div class="layui-input-block">
            <input type="text" name="usspeech" placeholder="请输入美式发音接口" value=""
                   class="layui-input">
            <!--            <tip>短语可以不填，但是不能修改默认的短语格式！</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">英式发音</label>
        <div class="layui-input-block">
            <input type="text" name="ukphone" placeholder="请输入英式发音" value=""
                   class="layui-input">
            <!--            <tip>短语可以不填，但是不能修改默认的短语格式！</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">英式发音接口</label>
        <div class="layui-input-block">
            <input type="text" name="ukspeech" placeholder="请输入英式发音接口" value=""
                   class="layui-input">
            <!--            <tip>短语可以不填，但是不能修改默认的短语格式！</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">词性</label>
        <div class="layui-input-block">
            <input type="text" name="synos" placeholder="请输入单词词性" value="{'n': 'null'},{'vt': 'null'}"
                   class="layui-input">
            <tip>词性可以不填，但不能修改默认的格式{格式如样例所示)！</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script th:src="@{/js/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        let keyword = decodeURI(document.URL).split('?')[1].split("=")[1];

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息',
                icon: 1
            }, function (index) {
                $.ajax({
                    url: '/twei/' + keyword,
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(data.field),
                    success: function (data) {
                        layer.msg(data.msg, {icon: 1, time: 800}, function () {
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                        if (data.code === 200) {
                            layer.close(index);
                        }
                    }
                });
            });
            return false;
        });

        form.verify({
            wordjudge: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!(/^[a-zA-Z]+$/.test(value))) {
                    return '必须填写的是单词';
                }
            }
        });
    });
</script>
</body>
</html>